import request from '@/router/axios';
import {baseUrl} from '@/config/env';

export const getList = (page, limit, params) => {
  return request({
    url: baseUrl + '/api/Role/getpages',
    method: 'get',
    params: {
      key:params.name==undefined?'':params.name,
      type:params.departmentName==undefined?'':params.departmentName,
      page,
      limit,
    }
  })
}
export const grantTree = () => {
  return request({
    url: baseUrl + '/api/menu/getButtons',
    method: 'get',
  })
}

export const buttonList = () => {
  return request({
    url: baseUrl + '/api/menu/buttonList',
    method: 'get',
  })
}

export const grant = (roleId, menuIds, btnIds) => {
  return request({
    url: baseUrl + '/api/Role/grant',
    method: 'post',
    data: {
      roleId,
      menuIds,
      btnIds
    }
  })
}

export const remove = (ids) => {
  return request({
    url: baseUrl + '/api/Role/remove',
    method: 'post',
    params: {
      ids,
    }
  })
}

export const add = (row) => {
  return request({
    url: baseUrl + '/api/Role/add',
    method: 'post',
    data: row
  })
}

export const update = (row) => {
  return request({
    url: baseUrl + '/api/Role/edit',
    method: 'post',
    data: row
  })
}

export const getModel = (id) => {
  return request({
    url: baseUrl + '/api/Role/getmodel',
    method: 'get',
    params: {
      id,
    }
  })
}

export const getRole = (roleId) => {
  return request({
    url: baseUrl + '/api/Role/torolelist',
    method: 'get',
    params: {
      roleId,
    }
  })
}

export const allrole = () => {
  return request({
    url: baseUrl + '/api/role/getroles',
    method: 'get'
  })
}
export const getRoleTree = () => {
  return request({
    url: baseUrl + '/api/Role/getpages',
    method: 'get',
    params: {
      page:1,
      limit:100,
    }
  })
}
